//
//  ShoppingLastlyTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/6/26.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "ShoppingLastlyTableViewCell.h"
#import "ShoppingLastlyCollectionViewCell.h"

static NSString *goodsCellID = @"goodsCellID";

@interface ShoppingLastlyTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UIImageView *lastlyIV;
@property (strong, nonatomic) UIView *goodsView;
@property (strong, nonatomic) UIView *goodsView1;
@property (strong, nonatomic) UIView *cornerView;

@property (strong, nonatomic) UIImageView *smallBackIV;
@property (strong, nonatomic) UILabel *loadMoreL;


@property (strong, nonatomic) UICollectionView *goodsCollectionView;

@end

@implementation ShoppingLastlyTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        
        [self.contentView addSubview:self.lastlyIV];
        [self.contentView addSubview:self.goodsView];
        [self.goodsView addSubview:self.cornerView];
        
        [self.cornerView addSubview:self.goodsCollectionView];
        [self.cornerView addSubview:self.smallBackIV];
        [self.cornerView addSubview:self.loadMoreL];
        
    }
    
    return self;
    
}

#pragma mark -更多最新点击事件
- (void)loadMoreGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"更多最新点击事件");
    
}

#pragma mark -delegate、datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 3;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ShoppingLastlyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:goodsCellID forIndexPath:indexPath];
    
    cell.backgroundColor = WhiteColor;
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"最新上架产品点击事件");
    
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.lastlyIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.contentView.mas_centerX);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.width.mas_equalTo(jisuan(750));
        make.height.mas_equalTo(jisuan(382));
        
    }];
    
    [self.goodsView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(Margin);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.lastlyIV.mas_bottom).with.offset(-jisuan(70));
        make.height.mas_equalTo(jisuan(321));
        
    }];
    
    [self.cornerView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.goodsView.mas_left).with.offset(0);
        make.right.mas_equalTo(weakSelf.goodsView.mas_right);
        make.top.mas_equalTo(weakSelf.goodsView.mas_top).with.offset(0);
        make.height.mas_equalTo(jisuan(321)); // 301
        
    }];
    
    [self.goodsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.cornerView.mas_left);
        make.top.mas_equalTo(weakSelf.cornerView.mas_top);
        make.right.mas_equalTo(weakSelf.cornerView.mas_right);
        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom).with.offset(-jisuan(61));
    
    }];
    
//    [self.smallBackIV mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.right.mas_equalTo(weakSelf.cornerView.mas_right).with.offset(-Margin);
//        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom).with.offset(-jisuan(10));
//        make.width.mas_equalTo(jisuan(20));
//        make.height.mas_equalTo(jisuan(20));
//    }];
//
//    [self.loadMoreL mas_makeConstraints:^(MASConstraintMaker *make) {
//
//            make.right.mas_equalTo(weakSelf.smallBackIV.mas_left).with.offset(-jisuan(5));
//            make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom);
//
////        make.centerX.mas_equalTo(weakSelf.cornerView.mas_centerX).with.offset(-jisuan(10));
////        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom);
//        make.height.mas_equalTo(jisuan(40));
//
//    }];
    
    
    [self.loadMoreL mas_makeConstraints:^(MASConstraintMaker *make) {
        
//        make.right.mas_equalTo(weakSelf.smallBackIV.mas_left).with.offset(-jisuan(5));
//        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom);

        make.centerX.mas_equalTo(weakSelf.cornerView.mas_centerX).with.offset(-jisuan(10));
        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom);
        make.height.mas_equalTo(jisuan(60));
        
    }];
    
    [self.smallBackIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.loadMoreL.mas_right).with.offset(jisuan(10));
        make.bottom.mas_equalTo(weakSelf.cornerView.mas_bottom).with.offset(-jisuan(20));
        make.width.mas_equalTo(jisuan(11));
        make.height.mas_equalTo(jisuan(20));
        
    }];
    
}

#pragma mark -lazy
- (UIImageView *)lastlyIV {
    
    if (!_lastlyIV) {
        
        _lastlyIV = [[UIImageView alloc] init];
        _lastlyIV.image = [UIImage imageNamed:@"shopLastlyBg"];
        _lastlyIV.contentMode = UIViewContentModeScaleAspectFit;
        _lastlyIV.backgroundColor = WhiteColor;
        
    }
    
    return _lastlyIV;
    
}

- (UIView *)goodsView {
    
    if (!_goodsView) {
        
        _goodsView = [[UIView alloc] init];
        _goodsView.backgroundColor = [UIColor clearColor];
        
        // Colorff2952
        _goodsView.layer.shadowColor = Colorb6b6b6.CGColor;
        _goodsView.layer.shadowOpacity = 0.35;
        _goodsView.layer.shadowRadius = jisuan(5);
        _goodsView.layer.shadowOffset = CGSizeMake(-3, 3);
        
    }
    
    return _goodsView;
    
}


- (UIView *)cornerView {
    
    if (!_cornerView) {
        
        _cornerView = [[UIView alloc] init];
        _cornerView.backgroundColor = WhiteColor;
        _cornerView.frame = CGRectMake(Margin, 0, SCREEN_WIDTH - Margin, jisuan(320));
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_cornerView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(jisuan(10), jisuan(10))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = _cornerView.bounds;
        //赋值
        maskLayer.path = path.CGPath;
        _cornerView.layer.mask = maskLayer;
        
    }
    
    return _cornerView;
    
}

- (UICollectionView *)goodsCollectionView {
    
    if (!_goodsCollectionView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(jisuan(257), jisuan(259));
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flowLayout.minimumLineSpacing = jisuan(1);
        flowLayout.minimumInteritemSpacing = jisuan(1);
        
        _goodsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _goodsCollectionView.backgroundColor = Colordddddd;
        
        _goodsCollectionView.bounces = NO;
        
        _goodsCollectionView.delegate = self;
        _goodsCollectionView.dataSource = self;
        
        _goodsCollectionView.showsVerticalScrollIndicator = NO;
        _goodsCollectionView.showsHorizontalScrollIndicator = NO;

        [_goodsCollectionView registerClass:[ShoppingLastlyCollectionViewCell class] forCellWithReuseIdentifier:goodsCellID];
        
        if (@available(iOS 11.0, *)) {
            
            _goodsCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        }
        
    }
    
    return _goodsCollectionView;
    
}

- (UIImageView *)smallBackIV {
    
    if (!_smallBackIV) {
        
        _smallBackIV = [[UIImageView alloc] init];
        _smallBackIV.image = [UIImage imageNamed:@"smallBackBg1"];
        _smallBackIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _smallBackIV;
}

- (UILabel *)loadMoreL {
    
    if (!_loadMoreL) {
        
        _loadMoreL = [[UILabel alloc] init];
        _loadMoreL.text = @"更多最新";
        _loadMoreL.textColor = Color1f89ff;
        _loadMoreL.font = Font(20);
        _loadMoreL.textAlignment = NSTextAlignmentRight;
        
        _loadMoreL.userInteractionEnabled = YES;
        UITapGestureRecognizer *loadMoreGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loadMoreGestureClick:)];
        [_loadMoreL addGestureRecognizer:loadMoreGesture];
        
    }
    
    return _loadMoreL;
    
}


@end


